home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group96a.txt / 000030_icon-group-sender _Mon Jan 29 10:05:18 1996.msg < prev    next >
Internet Message Format  |  1996-09-05  |  4KB

  1. Received: by cheltenham.cs.arizona.edu; Mon, 29 Jan 1996 12:22:42 MST
  2. Date: Mon, 29 Jan 1996 10:05:18 -0600 (CST)
  3. From: "Chris D. Tenaglia" <cdt@post.its.mcw.edu>
  4. To: Budi Rahardjo <rahardj@cc.umanitoba.ca>
  5. Cc: icon-group@cs.arizona.edu
  6. Subject: Re: processing utmp and/or wtmp with icon
  7. In-Reply-To: <slrn4gnrln.dpt.rahardj@phad.cc.umanitoba.ca>
  8. Message-Id: <Pine.ULT.3.90.960129100045.21685A-100000@post.its.mcw.edu>
  9. Mime-Version: 1.0
  10. Content-Type: TEXT/PLAIN; charset=US-ASCII
  11. Errors-To: icon-group-errors@cs.arizona.edu
  12. Status: O
  13.  
  14.  
  15. Here's a quick sample of my approach. It worked on solaris, but
  16. may need adjustments elsewhere. I did a man utmp to get the record
  17. layout. Anyway, the basic approach is: 
  18.  
  19. ########################### begin program #######################
  20. # file : get_utmp.icn
  21. # desc : reads /etc/utmp and outputs ascii lines
  22. # use  : get_utmp [>outfile]
  23. # warn : Worked on solaris, others? I don't know. Needs calc_date() finished
  24. #        to convert date to readable form. AS IS. NO WARANTY.
  25. #
  26. # update          by            what
  27. # 29-jan-1996     tenaglia      initial write
  28. #
  29. procedure main()
  30.  
  31.   ut_table := table("Unknown")
  32.   ut_table[0] := "EMPTY"
  33.   ut_table[1] := "RUN_LVL"
  34.   ut_table[2] := "BOOT_TIME"
  35.   ut_table[3] := "OLD_TIME"
  36.   ut_table[4] := "NEW_TIME"
  37.   ut_table[5] := "INIT_PROCESS"
  38.   ut_table[6] := "LOGIN_PROCESS"
  39.   ut_table[7] := "DEAD_PROCESS"
  40.   ut_table[8] := "ACCOUNTING"
  41.  
  42.   in := open("/etc/utmp","u")
  43.   while entry := reads(in,36) do
  44.     {
  45.     entry ? {
  46.         user := map(move(8),"\0"," ")
  47.         utab := map(move(4),"\0"," ")
  48.         utli := map(move(12),"\0"," ")
  49.         pid  := move(2)
  50.         utyp := move(2)
  51.         tsta := move(2)
  52.         esta := move(2)
  53.         utim := move(4)
  54.         }
  55.  
  56.     pid     := right(decimal(pid),6)
  57.     ut_type := left(ut_table[decimal(utyp)],16)
  58.     tstatus := right(decimal(tsta),4)
  59.     estatus := right(decimal(esta),4)
  60.     timus   := calc_date(decimal(utim))
  61.     write(user," ",utab," ",utli," ",pid," ",ut_type," ",tstatus," ",estatus," ",timus)
  62.     }
  63.   close(in)
  64.   end
  65.  
  66. #
  67. # determine the value of a raw hex number
  68. #
  69. procedure decimal(raw)
  70.   begin := 0
  71.   total := 0
  72.   every i := *raw to 1 by -1 do
  73.     {
  74.     value := ord(raw[i])
  75.     total+:= value * (256^begin)
  76.     begin+:= 1
  77.     }
  78.   return total
  79.   end
  80.  
  81. #
  82. # calculate date based from seconds after 1970
  83. # needs to be completed.
  84. #
  85. procedure calc_date(value)
  86.   static  leaps,spy,sply,cury
  87.   initial {
  88.           leaps := set([1972,1976,1980,1984,1988,1992,1996,2000,2004])
  89.           spy   := 31536000
  90.           sply  := 31622400
  91.       cury  := &date[1+:4]
  92.       }
  93.   if 0 > value > 1000000000 then return "Out of range"
  94.   yr := 1970
  95.   return value
  96.   repeat
  97.     {
  98.  
  99.     }
  100.   end
  101. #################### END CODE ###############################
  102.  
  103. Chris Tenaglia   (system manager)     |  cdt@post.its.mcw.edu
  104. Medical College of Wisconsin          |
  105. 8701 W. Watertown Plank Rd.           |  Ce que vous voyez est
  106. Milwaukee, WI 53226   (414)456-8765   |  ce que vous obtenez !
  107.  
  108. On 28 Jan 1996, Budi Rahardjo wrote:
  109.  
  110. > Date: 28 Jan 1996 21:46:33 GMT
  111. > From: Budi Rahardjo <rahardj@cc.umanitoba.ca>
  112. > To: icon-group@cs.arizona.edu
  113. > Subject: processing utmp and/or wtmp with icon
  114. > We are planning to write a program which converts utmp/wtmp file
  115. > into somekind of database (delimitted, flat file would be good enough).
  116. > The database is used to produces statistics such as usage, number of logins, 
  117. > how many hours one has logged in to a system this month, etc.
  118. > We want to produce this stats in real time too.
  119. > Actually, I have written this in perl but wanted to make it an executable.
  120. > Icon seems to be a natural approach ( don't want to go to C or C++).
  121. > Before I start rolling the design, has anybody done this? 
  122. > Any tips.
  123. > Thanks
  124. > -- budi
  125. > -- 
  126. > Budi Rahardjo <Budi_Rahardjo@UManitoba.Ca>
  127. > #include <std-disclaimer.h>
  128.